<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>期刊论文管理系统 - 登录</title>

    <!-- 引入Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        body {
            background-image: url('images/background.jpg'); /* 背景图片路径 */
            background-size: cover; /* 使背景图覆盖整个页面 */
            background-position: center; /* 背景图居中 */
            font-family: 'Roboto', sans-serif;
            height: 100vh;  /* 让页面充满整个视口 */
            margin: 0;
            display: flex;
            justify-content: center;  /* 居中对齐 */
            align-items: center;  /* 垂直居中 */
        }

        .container {
            background-color: rgba(255, 255, 255, 0.9); /* 半透明白色背景 */
            padding: 40px;
            border-radius: 15px; /* 圆角 */
            max-width: 450px; /* 限制宽度 */
            width: 100%;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); /* 增加阴影效果 */
        }

        h2, h4 {
            font-weight: 600; /* 加粗字体 */
            color: #333;
        }

        .form-group input {
            font-size: 16px;
            padding: 12px;
            border-radius: 8px;
            border: 1px solid #ddd;
            margin-bottom: 15px;
            width: 100%;
        }

        .form-group input:focus {
            border-color: #007bff;
            box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
        }

        .btn {
            border-radius: 25px;
            padding: 12px;
            font-size: 18px;
            width: 100%;
            transition: all 0.3s ease;
        }

        .btn-primary {
            background: linear-gradient(90deg, #00b4db, #0083b0);
            border: none;
            color: white;
        }

        .btn-primary:hover {
            background: linear-gradient(90deg, #0083b0, #00b4db);
            transform: translateY(-3px);
        }

        .footer {
            position: fixed;
            bottom: 10px;
            width: 100%;
            text-align: center;
            color: #ddd;
        }

        .footer p {
            margin: 0;
            font-size: 14px;
        }

        p.text-center {
            font-size: 16px;
        }

        p.text-center a {
            text-decoration: none;
            color: #007bff;
            font-weight: bold;
        }

        p.text-center a:hover {
            color: #0056b3;
        }

    </style>
</head>
<body>
<div class="container">
    <h2 class="text-center mb-3">期刊论文管理系统</h2>
    <h4 class="text-center mb-4">用户登录</h4>

    <!-- 登录表单 -->
    <form id="loginForm">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" class="form-control" id="username" placeholder="请输入用户名" required>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" placeholder="请输入密码" required>
        </div>
        <button type="submit" class="btn btn-primary">登录</button>
    </form>

    <!-- 注册链接 -->
    <p class="text-center mt-3">
        还没有账户？ <a href="register.html">注册</a>
    </p>
</div>

<!-- 引入Bootstrap和jQuery JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

<script>
    // 登录请求
    document.getElementById("loginForm").addEventListener("submit", function(event) {
        event.preventDefault();

        var username = document.getElementById('username').value;
        var password = document.getElementById('password').value;

        fetch('http://127.0.0.1:8080/user/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ username: username, password: password })
        })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    // 登录成功后跳转到主页
                    location.href = '/journal.html';
                } else {
                    alert(data.errorMsg || '用户名或密码错误');
                }
            })
            .catch(error => {
                console.log(error);
                alert('登录失败，请稍后再试');
            });
    });
</script>
</body>
</html>
